import React, { Component } from 'react'
import './Header.css'
export default class Header extends Component {
  state = {
    todoName: "",
  };
  handle = (e) => {
    this.setState({
      todoName: e.target.value.trim(),
    });
  };

  keyUpheader = (e) => {
    const {todoName}=this.state
    if (e.keyCode !== 13 || !todoName) return;
    // 添加数据,调用app里的方法,传输实参(任务）
    const {getTdoName}=this.props
    getTdoName(todoName);
    this.setState({
      todoName:'',
    })


    

  };


  render() {
    const { todoName } = this.state;
    return (
      <div className="todo-header">
        <input
          type="text"
          value={todoName}
          onChange={this.handle}
          onKeyUp={this.keyUpheader}
        />
      </div>
    );
  }
}
